home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / hopes_babysitting_maze.swf / scripts / __Packages / Classes / bsmLevel.as < prev    next >
Text File  |  2011-08-19  |  13KB  |  448 lines

  1. class Classes.bsmLevel
  2. {
  3.    var BABYTIMER_MAX = 15;
  4.    var SPECIALTIMER_MAX = 11;
  5.    var hdAssetID = "mc_HD";
  6.    var z_hd = 5;
  7.    var z_playerMin = 200;
  8.    var z_enemyMin = 100;
  9.    var z_iconMin = 10;
  10.    var n_timerMax = 60;
  11.    var SSP = {x:530,y:53};
  12.    function bsmLevel(t_engine)
  13.    {
  14.       this.engine = t_engine;
  15.    }
  16.    function get timer()
  17.    {
  18.       Math.ceil(this.n_timer);
  19.    }
  20.    function step(t_elapsed)
  21.    {
  22.       this.babyTimer -= t_elapsed;
  23.       if(this.babyTimer < 0)
  24.       {
  25.          var _loc3_ = this.engine.gameRoot.house_mc.crib_mc.baby_mc;
  26.          if(this.babySadness == 0)
  27.          {
  28.             _loc3_.gotoAndStop("happy");
  29.          }
  30.          else if(this.babySadness <= 2)
  31.          {
  32.             _loc3_.gotoAndStop("cry");
  33.          }
  34.          _loc3_.anim.gotoAndPlay(1);
  35.          this.babySadness = this.babySadness + 1;
  36.          this.babyTimer = this.BABYTIMER_MAX;
  37.       }
  38.       this.n_timer -= t_elapsed;
  39.       if(this.n_timer <= 0)
  40.       {
  41.          this.n_timer = 0;
  42.          this.engine.gameOver();
  43.          return undefined;
  44.       }
  45.       if(this.n_timer < 20)
  46.       {
  47.          if(this.alertLowTime)
  48.          {
  49.             this.engine.gameRoot.mc_watch.gotoAndPlay("twentysec");
  50.             this.alertLowTime = false;
  51.          }
  52.          else if(this.n_timer < 10 && this.alertWarningTime)
  53.          {
  54.             this.engine.gameRoot.mc_watch.gotoAndPlay("tensec");
  55.             this.alertWarningTime = false;
  56.          }
  57.       }
  58.       this.engine.gameRoot.mc_clock.mc_anim.gotoAndStop(this.clockFrames - Math.floor(this.clockFrames * (this.n_timer / this.n_timerMax)));
  59.       this.player.update(t_elapsed);
  60.       this.stepEnemy(t_elapsed);
  61.       if(!this.player.hidden)
  62.       {
  63.          this.player.update(t_elapsed);
  64.          this.runEntityHD();
  65.          this.player.move();
  66.          this.runSwingHD();
  67.          if(this.babyReady)
  68.          {
  69.             this.runBabyHD();
  70.          }
  71.          else
  72.          {
  73.             this.runIconHD(t_elapsed);
  74.          }
  75.       }
  76.       this.player.render();
  77.    }
  78.    function runSwingHD()
  79.    {
  80.       if(Math.sqrt((this.player.x - this.SSP.x) * (this.player.x - this.SSP.x) + (this.player.y - this.SSP.y) * (this.player.y - this.SSP.y)) < 30)
  81.       {
  82.          this.engine.gameRoot.house_mc.swingset_mc.play();
  83.       }
  84.    }
  85.    function start(t_path)
  86.    {
  87.       this.reset();
  88.       this.clear();
  89.       this.path = t_path;
  90.       this.attachHD();
  91.       this.iconsFound = 0;
  92.       this.iconsTotal = this.iconData.length;
  93.       this.babyReady = false;
  94.       this.spawnPlayer();
  95.       this.spawnIcons();
  96.       this.setSpecial();
  97.       this.clockFrames = this.engine.gameRoot.mc_clock.mc_anim._totalFrames;
  98.       this.a_enemy = [];
  99.       this.spawnEnemy();
  100.    }
  101.    function setSpecial()
  102.    {
  103.       var _loc2_ = this.a_icons.length;
  104.       var _loc3_ = 0;
  105.       while(true)
  106.       {
  107.          _loc2_;
  108.          if(!_loc2_--)
  109.          {
  110.             break;
  111.          }
  112.          if(this.a_icons[_loc2_].specialNum == this.currentSpecial && this.a_icons[_loc2_].isActive)
  113.          {
  114.             this.a_icons[_loc2_].goSpecial(this.specialTimer);
  115.             _loc3_ = _loc3_ + 1;
  116.          }
  117.       }
  118.       if(_loc3_ > 1)
  119.       {
  120.          this.specialTimer += 6;
  121.       }
  122.    }
  123.    function reset()
  124.    {
  125.       this.n_timer = this.n_timerMax;
  126.       this.specialTimer = this.SPECIALTIMER_MAX;
  127.       this.currentSpecial = 0;
  128.       this.babyTimer = this.BABYTIMER_MAX;
  129.       this.babySadness = 0;
  130.       this.engine.gameRoot.house_mc.crib_mc.baby_mc.gotoAndStop("happy");
  131.       this.z_playerCurrent = this.z_playerMin;
  132.       this.z_iconCurrent = this.z_iconMin;
  133.       this.z_enemyCurrent = this.z_enemyMin;
  134.    }
  135.    function clear()
  136.    {
  137.       this.player.clear();
  138.       this.player = null;
  139.       this.alertLowTime = true;
  140.       this.alertWarningTime = true;
  141.       this.engine.gameRoot.babyArrow_mc.gotoAndStop("off");
  142.       this.clearIcons();
  143.       this.clearEnemy();
  144.    }
  145.    function attachHD()
  146.    {
  147.       this.hd = this.path.attachMovie(this.hdAssetID,"hd",this.z_hd);
  148.       this.generateAIPoints();
  149.    }
  150.    function generateAIPoints()
  151.    {
  152.       this.a_aiPoints = [];
  153.       this.a_aiPoints.push({point:"point1",adj:["point2","point8"]});
  154.       this.a_aiPoints.push({point:"point2",adj:["point1","point3","point7"]});
  155.       this.a_aiPoints.push({point:"point3",adj:["point2","point4"]});
  156.       this.a_aiPoints.push({point:"point4",adj:["point3","point5"]});
  157.       this.a_aiPoints.push({point:"point5",adj:["point4","point6"]});
  158.       this.a_aiPoints.push({point:"point6",adj:["point5","point7","point18"]});
  159.       this.a_aiPoints.push({point:"point7",adj:["point6","point2","point8"]});
  160.       this.a_aiPoints.push({point:"point8",adj:["point7","point1","point9"]});
  161.       this.a_aiPoints.push({point:"point9",adj:["point8","point10","point13"]});
  162.       this.a_aiPoints.push({point:"point10",adj:["point9","point11"]});
  163.       this.a_aiPoints.push({point:"point11",adj:["point10","point12"]});
  164.       this.a_aiPoints.push({point:"point12",adj:["point11","point13"]});
  165.       this.a_aiPoints.push({point:"point13",adj:["point12","point14","point9"]});
  166.       this.a_aiPoints.push({point:"point14",adj:["point13","point15","point19"]});
  167.       this.a_aiPoints.push({point:"point15",adj:["point14","point20"]});
  168.       this.a_aiPoints.push({point:"point16",adj:["point20","point17"]});
  169.       this.a_aiPoints.push({point:"point17",adj:["point16","point18"]});
  170.       this.a_aiPoints.push({point:"point18",adj:["point17","point19"]});
  171.       this.a_aiPoints.push({point:"point19",adj:["point18","point14"]});
  172.       this.a_aiPoints.push({point:"point20",adj:["point15","point16","point21"]});
  173.       this.a_aiPoints.push({point:"point21",adj:["point20","point22"]});
  174.       this.a_aiPoints.push({point:"point22",adj:["point21","point23","point24"]});
  175.       this.a_aiPoints.push({point:"point23",adj:["point22"]});
  176.       this.a_aiPoints.push({point:"point24",adj:["point22","point25"]});
  177.       this.a_aiPoints.push({point:"point25",adj:["point24","point8"]});
  178.    }
  179.    function runEntityHD()
  180.    {
  181.       var _loc2_ = this.a_enemy.length;
  182.       while(true)
  183.       {
  184.          _loc2_;
  185.          if(!_loc2_--)
  186.          {
  187.             break;
  188.          }
  189.          if(this.player.mc.hitTest(this.a_enemy[_loc2_].mc))
  190.          {
  191.             this.player.hit(this.a_enemy[_loc2_]);
  192.             this.a_enemy[_loc2_].hitReact();
  193.          }
  194.       }
  195.    }
  196.    function runIconHD(el)
  197.    {
  198.       var _loc2_ = this.a_icons.length;
  199.       while(true)
  200.       {
  201.          _loc2_;
  202.          if(!_loc2_--)
  203.          {
  204.             break;
  205.          }
  206.          if(this.a_icons[_loc2_].isSpecial)
  207.          {
  208.             this.a_icons[_loc2_].decSpecial(el);
  209.          }
  210.          if(this.a_icons[_loc2_].isActive && Math.abs(this.player.x - this.a_icons[_loc2_].x) < 20)
  211.          {
  212.             if(this.a_icons[_loc2_].mc.hitTest(this.player.mc))
  213.             {
  214.                if(this.a_icons[_loc2_].isSpecial)
  215.                {
  216.                   this.currentSpecial = this.currentSpecial + 1;
  217.                   this.setSpecial();
  218.                }
  219.                this.a_icons[_loc2_].pickup();
  220.                this.engine.addScore(this.a_icons[_loc2_].value);
  221.                this.iconsFound = this.iconsFound + 1;
  222.                if(this.iconsFound == this.iconsTotal)
  223.                {
  224.                   this.startBaby();
  225.                }
  226.             }
  227.          }
  228.       }
  229.    }
  230.    function runBabyHD()
  231.    {
  232.       if(this.engine.gameRoot.babyArrow_mc.hitTest(this.player.mc))
  233.       {
  234.          this.engine.gameRoot.babyArrow_mc.gotoAndStop("off");
  235.          this.engine.startScript("meetBaby");
  236.       }
  237.    }
  238.    function startBaby()
  239.    {
  240.       this.engine.gameRoot.babyArrow_mc.gotoAndStop("on");
  241.       this.engine.playSound("pickupFinal");
  242.       this.babyReady = true;
  243.    }
  244.    function findPoint(t_point)
  245.    {
  246.       var _loc2_ = this.a_aiPoints.length;
  247.       while(true)
  248.       {
  249.          _loc2_;
  250.          if(!_loc2_--)
  251.          {
  252.             break;
  253.          }
  254.          if(t_point == this.a_aiPoints[_loc2_].point)
  255.          {
  256.             return _loc2_;
  257.          }
  258.       }
  259.       return 0;
  260.    }
  261.    function findAdjacentPoint(t_point)
  262.    {
  263.       var _loc3_ = undefined;
  264.       var _loc2_ = undefined;
  265.       var _loc6_ = undefined;
  266.       _loc3_ = this.a_aiPoints[t_point].adj;
  267.       var _loc5_ = _loc3_.length;
  268.       _loc2_ = Math.ceil(Math.random() * _loc3_.length) - 1;
  269.       if(_loc2_ < 0)
  270.       {
  271.          _loc2_ = 0;
  272.       }
  273.       _loc2_ = _loc3_[_loc2_];
  274.       if(_loc2_ == undefined)
  275.       {
  276.          trace("OMG ERROR");
  277.          return t_point;
  278.       }
  279.       return this.findPoint(_loc2_);
  280.    }
  281.    function findFurthestPointFromPlayer(t_point)
  282.    {
  283.       var a_adj;
  284.       var t_pointMC;
  285.       var n_dist;
  286.       var n_winner;
  287.       var n_result;
  288.       var xDiff;
  289.       var yDiff;
  290.       var d;
  291.       a_adj = this.a_aiPoints[t_point].adj;
  292.       n_dist = 0;
  293.       d = a_adj.length;
  294.       while(d--)
  295.       {
  296.          t_pointMC = eval(this.hd + "." + a_adj[d]);
  297.          xDiff = this.player.x - t_pointMC._x;
  298.          yDiff = this.player.y - t_pointMC._y;
  299.          n_result = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
  300.          if(n_result > n_dist)
  301.          {
  302.             n_dist = n_result;
  303.             n_winner = a_adj[d];
  304.          }
  305.       }
  306.       if(n_winner == undefined)
  307.       {
  308.          trace("OMG ERROR");
  309.          return t_point;
  310.       }
  311.       return this.findPoint(n_winner);
  312.    }
  313.    function findClosestPointToPlayer(t_point)
  314.    {
  315.       var a_adj;
  316.       var t_pointMC;
  317.       var n_dist;
  318.       var n_winner;
  319.       var n_result;
  320.       var xDiff;
  321.       var yDiff;
  322.       var d;
  323.       a_adj = this.a_aiPoints[t_point].adj;
  324.       n_dist = 2000;
  325.       d = a_adj.length;
  326.       while(d--)
  327.       {
  328.          t_pointMC = eval(this.hd + "." + a_adj[d]);
  329.          xDiff = this.player.x - t_pointMC._x;
  330.          yDiff = this.player.y - t_pointMC._y;
  331.          n_result = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
  332.          if(n_result < n_dist)
  333.          {
  334.             n_dist = n_result;
  335.             n_winner = a_adj[d];
  336.          }
  337.       }
  338.       if(n_winner == undefined)
  339.       {
  340.          trace("OMG ERROR");
  341.          return t_point;
  342.       }
  343.       return this.findPoint(n_winner);
  344.    }
  345.    function spawnPlayer()
  346.    {
  347.       this.player = new Classes.bsmPlayer(this.playerData,this);
  348.       this.player.spawn(this.path,this.z_playerCurrent);
  349.       this.player.mc.gotoAndStop("glow");
  350.       this.z_playerCurrent = this.z_playerCurrent + 1;
  351.    }
  352.    function stepEnemy(t_elapsed)
  353.    {
  354.       var _loc2_ = this.a_enemy.length;
  355.       while(true)
  356.       {
  357.          _loc2_;
  358.          if(!_loc2_--)
  359.          {
  360.             break;
  361.          }
  362.          this.a_enemy[_loc2_].step(t_elapsed);
  363.       }
  364.    }
  365.    function spawnEnemy()
  366.    {
  367.       this.a_enemy = [];
  368.       var _loc3_ = this.enemyData.length;
  369.       while(true)
  370.       {
  371.          _loc3_;
  372.          if(!_loc3_--)
  373.          {
  374.             break;
  375.          }
  376.          var _loc2_ = new Classes.bsmEnemy(this.enemyData[_loc3_],this);
  377.          this.a_enemy.push(_loc2_);
  378.          _loc2_.spawn(this.path,this.z_enemyCurrent);
  379.          this.z_enemyCurrent = this.z_enemyCurrent + 1;
  380.       }
  381.    }
  382.    function spawnSpecific(t_type)
  383.    {
  384.       var _loc3_ = this.enemyData.length;
  385.       while(true)
  386.       {
  387.          _loc3_;
  388.          if(!_loc3_--)
  389.          {
  390.             break;
  391.          }
  392.          if(this.enemyData[_loc3_].type == t_type)
  393.          {
  394.             var _loc2_ = new Classes.bsmEnemy(this.enemyData[_loc3_],this);
  395.             this.a_enemy.push(_loc2_);
  396.             _loc2_.spawn(this.path,this.z_enemyCurrent);
  397.             this.z_enemyCurrent = this.z_enemyCurrent + 1;
  398.          }
  399.       }
  400.    }
  401.    function clearEnemy()
  402.    {
  403.       var _loc2_ = this.a_enemy.length;
  404.       while(true)
  405.       {
  406.          _loc2_;
  407.          if(!_loc2_--)
  408.          {
  409.             break;
  410.          }
  411.          this.a_enemy[_loc2_].clear();
  412.       }
  413.       this.a_enemy = [];
  414.    }
  415.    function spawnIcons()
  416.    {
  417.       this.a_icons = [];
  418.       var _loc3_ = this.iconData.length;
  419.       var _loc2_ = undefined;
  420.       while(true)
  421.       {
  422.          _loc3_;
  423.          if(!_loc3_--)
  424.          {
  425.             break;
  426.          }
  427.          _loc2_ = new Classes.bsmIcon(this.iconData[_loc3_],this,this.iconFrameNum);
  428.          this.a_icons.push(_loc2_);
  429.          _loc2_.spawn(this.path,this.z_iconCurrent);
  430.          this.z_iconCurrent = this.z_iconCurrent + 1;
  431.       }
  432.    }
  433.    function clearIcons()
  434.    {
  435.       var _loc2_ = this.a_icons.length;
  436.       while(true)
  437.       {
  438.          _loc2_;
  439.          if(!_loc2_--)
  440.          {
  441.             break;
  442.          }
  443.          this.a_icons[_loc2_].clear();
  444.       }
  445.       this.a_icons = [];
  446.    }
  447. }
  448.